package cn.usbtg.jfinal.plugin.autoroute.converter;

import cn.usbtg.jfinal.plugin.autoroute.AutoRoutesAnnotation;
import cn.usbtg.jfinal.plugin.autoroute.ControllerNameConverter;

import java.util.List;

/**
 * 控制器名称转换器（className去掉指定的后缀）
 */
public class SuffixControllerNameConverter implements ControllerNameConverter {

    @Override
    public String convert(String className) {
        String url = className;
        List<String> clsSuffixs = AutoRoutesAnnotation.getInstance().getClsSuffixs();
        for (String clsSuffix : clsSuffixs) {
            if (url.toLowerCase().endsWith(clsSuffix.toLowerCase())) {
                url = url.substring(0, url.length() - clsSuffix.length());
            }
        }
        return url;
    }
}